import { ScrollView, View } from "@tarojs/components";
import { Component, ReactNode } from "react";
import "./index.scss";
import { AtNavBar } from "taro-ui";
import Taro from "@tarojs/taro";
import Req from "../../utils/request";
import { title } from "process";
export default class NoticeDetail extends Component {
  state = {
    info: {},
    title:"通知详情"
  };
  get noticeId() {
    const { router } = Taro.getCurrentInstance();
    return router?.params.id ?? "";
  }
  get isMessage(){
    const {router} = Taro.getCurrentInstance();
    if(router?.params.notice == '2'){
      return true
    } 
    return false;
  }
  componentDidMount(): void {
    if (this.noticeId) {
      let url = "/notice/" + this.noticeId
      if(this.isMessage){
        url = '/message/'+this.noticeId;
      }
      Req.get(url)
        .then((r) => {
          if (r.code === 200) {
            this.setState({
              info: r.data,
            });
          }
        })
        .catch((e) => {});
    }
  }
  componentDidShow(){
    if(this.isMessage){
      Taro.setNavigationBarTitle({
        title:'消息详情'
      })
      this.setState({
        title:"消息详情"
      })
    } 
  }
  render(): ReactNode {
    const { info,title }: any = this.state;

    return (
      <View className="notice-container">
        <AtNavBar
          onClickLeftIcon={() => {
            Taro.navigateBack();
          }}
          leftIconType="chevron-left"
          color="#3051BE"
        >
          <View>{title}</View>
        </AtNavBar>
        <ScrollView className="notice-scrollbox">
          <View className="at-article">
            <View className="at-article__h1">{info.title}</View>
          </View>
          <View className="at-article__content">
            <View className="at-article__p">{info.memo}</View>
          </View>
        </ScrollView>
      </View>
    );
  }
}
